import Cookies from 'js-cookie';

const app = {
  state: {
    sidebar: {
      opened: true,
      withoutAnimation: false,
    },
    device: 'desktop',
    serverUrl: '',
    weixinDialogStatus: false,
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('sidebarStatus', 1)
      } else {
        Cookies.set('sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
    },
    TOGGLE_DEVICE: (state, value) => {
      state.device = value
    },
    CLOSE_SIDEBAR: (state, withoutAnimation) => {
      Cookies.set('sidebarStatus', 1)
      state.sidebar.opened = false
      state.sidebar.withoutAnimation = withoutAnimation
    },
    TOGGLE_WEIXIN: (state, value) => {
      state.weixinDialogStatus = value
    }
  },
  actions: {
    ToggleSideBar: ({
      commit
    }) => {
      commit('TOGGLE_SIDEBAR');
    },
    ToggleDevice: ({
      commit
    }, value) => {
      commit('TOGGLE_DEVICE', value)
    },
    CloseSideBar({
      commit
    }, {
      withoutAnimation
    }) {
      commit('CLOSE_SIDEBAR', withoutAnimation)
    },
    ToggleWeixin: ({
      commit
    }, value) => {
      commit('TOGGLE_WEIXIN', value)
    }
  }
}
export default app;
